package net.vz.geoapi;

import java.util.HashMap;
import java.util.Map;

import net.vz.geoapi.utils.GeoApiInputException;

/**
 * search with a latitude/longitude coordinate pair and an optional radius distance
 * 
 * @author sirrgang
 *
 */
public class KeywordSearch extends GeneralSearch 
{
    private static String URL_SEARCH_METHOD = "keyword-search";
    
    private String query  = null;
    private String entity = null;
    
    public KeywordSearch(String _apiKey, String _version) {
        super(_apiKey, _version);
    }
    
    public KeywordSearch(String _apiKey) {
        super(_apiKey, DEFAULT_VERSION);
    }
    
    public void setQuery(String _query) {
        this.query = _query;
    }
    
    public void setEntityGuid(String _entity) {
        this.entity  = _entity;
    }
    
    @Override
    protected void validateInput() throws GeoApiInputException {
        super.validateInput();
        
        if (this.query == null || this.query.length() == 0 || this.getLimit() == 0) {
            throw new GeoApiInputException();
        }
    }
    
    @Override
    protected String getSearchMethod() {
        if (this.entity != null) {
            return "e/" + this.entity + "/" + URL_SEARCH_METHOD;
        }
        return URL_SEARCH_METHOD;
    }
    
    @Override
    protected Map<String, String> getRequestParams() {
        HashMap<String, String> map = new HashMap<String, String>();
        
        map.put("q", this.query);
        
        return map;
    }
}
